import {Component, OnInit} from "@angular/core";
import {FormBuilder, FormGroup, Validators} from "@angular/forms";

@Component({selector: "app", templateUrl: "app.component.html"})
export class AppComponent implements OnInit {
    registerForm: FormGroup;
    submitted = false;

    constructor(private formBuilder: FormBuilder) {
    }

    ngOnInit() {
        // TODO: 请补充表单设置
        this.registerForm = this.formBuilder.group(
            {
                firstName: ["", Validators.required],
                lastName: ["", Validators.required],
                email: ["", [Validators.required, Validators.email]],
                age: ["", [Validators.required, Validators.min(0), Validators.max(150)]],
                password: ["", [Validators.required, Validators.minLength(6)]]
            }
        );
    }

    // convenience getter for easy access to form fields
    get f() {
        return this.registerForm.controls;
    }

    onSubmit() {
        this.submitted = true;

        // TODO: 请编写表单提交后的代码

        console.log(this.registerForm.value)
    }

    onReset() {
        this.submitted = false;
        this.registerForm.reset();
    }
}
